import cv2
import numpy as np


def onchange(value):
    print(value)
    pass


cv2.namedWindow('trackbar', cv2.WINDOW_NORMAL)

# 创建R颜色拖拽进度条
cv2.createTrackbar('R', 'trackbar', 0, 255, onchange)
cv2.createTrackbar('G', 'trackbar', 0, 255, onchange)
cv2.createTrackbar('B', 'trackbar', 0, 255, onchange)

# 创建一个三维数组
img = np.zeros((480, 640, 3), np.uint8)

while True:
    cv2.imshow('trackbar', img)

    r = cv2.getTrackbarPos('R', 'trackbar')
    g = cv2.getTrackbarPos('G', 'trackbar')
    b = cv2.getTrackbarPos('B', 'trackbar')
    # img赋值，OpenCV的色彩空间 bgr
    img[:] = [b, g, r]
    key = cv2.waitKey(10)
    if key & 0xFF == ord('q'):
        break
cv2.destroyAllWindows()
